#include "CAnimationEngine.h"
#include <fstream>
#include <string.h>
using std::string;
using std::ifstream;
using std::ios_base;

CAnimationEngine *CAnimationEngine::GetInstance()
{
	static CAnimationEngine Instance;
	return &Instance;
}
bool CAnimationEngine::LoadAllAnimations()
{
	Animation * pNewAnim = new Animation;
	pNewAnim->m_FrameList.resize(4);
	pNewAnim->m_FrameList[0].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/Char/Gothic_ani/Idle/GothicIdle_F1.tga");
	pNewAnim->m_FrameList[1].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/Char/Gothic_ani/Idle/GothicIdle_F2.tga");
	pNewAnim->m_FrameList[2].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/Char/Gothic_ani/Idle/GothicIdle_F3.tga");
	pNewAnim->m_FrameList[3].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/Char/Gothic_ani/Idle/GothicIdle_F4.tga");
	pNewAnim->m_FrameList[0].m_fFrameTime = 0.25f;
	pNewAnim->m_FrameList[1].m_fFrameTime = 0.25f;
	pNewAnim->m_FrameList[2].m_fFrameTime = 0.25f;
	pNewAnim->m_FrameList[3].m_fFrameTime = 0.25f;
	m_vAnimations.push_back(pNewAnim);

	Animation * pNewAnim1 = new Animation;
	pNewAnim1->m_FrameList.resize(5);
	pNewAnim1->m_FrameList[0].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/Char/Gothic_ani/Jump/GothicJump_F1.tga");
	pNewAnim1->m_FrameList[1].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/Char/Gothic_ani/Jump/GothicJump_F2.tga");
	pNewAnim1->m_FrameList[2].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/Char/Gothic_ani/Jump/GothicJump_F3.tga");
	pNewAnim1->m_FrameList[3].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/Char/Gothic_ani/Jump/GothicJump_F4.tga");
	pNewAnim1->m_FrameList[4].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/Char/Gothic_ani/Jump/GothicJump_F5.tga");
	pNewAnim1->m_FrameList[0].m_fFrameTime = 0.25f;
	pNewAnim1->m_FrameList[1].m_fFrameTime = 0.25f;
	pNewAnim1->m_FrameList[2].m_fFrameTime = 0.25f;
	pNewAnim1->m_FrameList[3].m_fFrameTime = 0.25f;
	pNewAnim1->m_FrameList[4].m_fFrameTime = 0.25f;
	m_vAnimations.push_back(pNewAnim1);

	Animation * pNewAnim2 = new Animation;
	pNewAnim2->m_FrameList.resize(4);
	pNewAnim2->m_FrameList[0].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/Char/Gothic_ani/Walk/GothicWalk_F1.tga");
	pNewAnim2->m_FrameList[1].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/Char/Gothic_ani/Walk/GothicWalk_F2.tga");
	pNewAnim2->m_FrameList[2].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/Char/Gothic_ani/Walk/GothicWalk_F3.tga");
	pNewAnim2->m_FrameList[3].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/Char/Gothic_ani/Walk/GothicWalk_F4.tga");
	pNewAnim2->m_FrameList[0].m_fFrameTime = 0.25f;
	pNewAnim2->m_FrameList[1].m_fFrameTime = 0.25f;
	pNewAnim2->m_FrameList[2].m_fFrameTime = 0.25f;
	pNewAnim2->m_FrameList[3].m_fFrameTime = 0.25f;
	m_vAnimations.push_back(pNewAnim2);

	Animation * pNewAnim3 = new Animation;
	pNewAnim3->m_FrameList.resize(4);
	pNewAnim3->m_FrameList[0].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/Char/Greek_ani/Idle/GreekIdle_F1.tga");
	pNewAnim3->m_FrameList[1].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/Char/Greek_ani/Idle/GreekIdle_F2.tga");
	pNewAnim3->m_FrameList[2].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/Char/Greek_ani/Idle/GreekIdle_F3.tga");
	pNewAnim3->m_FrameList[3].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/Char/Greek_ani/Idle/GreekIdle_F4.tga");
	pNewAnim3->m_FrameList[0].m_fFrameTime = 0.25f;
	pNewAnim3->m_FrameList[1].m_fFrameTime = 0.25f;
	pNewAnim3->m_FrameList[2].m_fFrameTime = 0.25f;
	pNewAnim3->m_FrameList[3].m_fFrameTime = 0.25f;
	m_vAnimations.push_back(pNewAnim3);

	Animation * pNewAnim4 = new Animation;
	pNewAnim4->m_FrameList.resize(5);
	pNewAnim4->m_FrameList[0].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/Char/Greek_ani/Jump/GreekJump_F1.tga");
	pNewAnim4->m_FrameList[1].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/Char/Greek_ani/Jump/GreekJump_F2.tga");
	pNewAnim4->m_FrameList[2].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/Char/Greek_ani/Jump/GreekJump_F3.tga");
	pNewAnim4->m_FrameList[3].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/Char/Greek_ani/Jump/GreekJump_F4.tga");
	pNewAnim4->m_FrameList[4].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/Char/Greek_ani/Jump/GreekJump_F5.tga");
	pNewAnim4->m_FrameList[0].m_fFrameTime = 0.25f;
	pNewAnim4->m_FrameList[1].m_fFrameTime = 0.25f;
	pNewAnim4->m_FrameList[2].m_fFrameTime = 0.25f;
	pNewAnim4->m_FrameList[3].m_fFrameTime = 0.25f;
	pNewAnim4->m_FrameList[4].m_fFrameTime = 0.25f;
	m_vAnimations.push_back(pNewAnim4);

	Animation * pNewAnim5 = new Animation;
	pNewAnim5->m_FrameList.resize(4);
	pNewAnim5->m_FrameList[0].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/Char/Greek_ani/Walk/GreekWalk_F1.tga");
	pNewAnim5->m_FrameList[1].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/Char/Greek_ani/Walk/GreekWalk_F2.tga");
	pNewAnim5->m_FrameList[2].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/Char/Greek_ani/Walk/GreekWalk_F3.tga");
	pNewAnim5->m_FrameList[3].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/Char/Greek_ani/Walk/GreekWalk_F4.tga");
	pNewAnim5->m_FrameList[0].m_fFrameTime = 0.25f;
	pNewAnim5->m_FrameList[1].m_fFrameTime = 0.25f;
	pNewAnim5->m_FrameList[2].m_fFrameTime = 0.25f;
	pNewAnim5->m_FrameList[3].m_fFrameTime = 0.25f;
	m_vAnimations.push_back(pNewAnim5);

	Animation * pNewAnim6 = new Animation;
	pNewAnim6->m_FrameList.resize(4);
	pNewAnim6->m_FrameList[0].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/Char/MidEvil_ani/Idle/TGA/MidEvilIdle_F1.tga");
	pNewAnim6->m_FrameList[1].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/Char/MidEvil_ani/Idle/TGA/MidEvilIdle_F2.tga");
	pNewAnim6->m_FrameList[2].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/Char/MidEvil_ani/Idle/TGA/MidEvilIdle_F3.tga");
	pNewAnim6->m_FrameList[3].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/Char/MidEvil_ani/Idle/TGA/MidEvilIdle_F4.tga");
	pNewAnim6->m_FrameList[0].m_fFrameTime = 0.25f;
	pNewAnim6->m_FrameList[1].m_fFrameTime = 0.25f;
	pNewAnim6->m_FrameList[2].m_fFrameTime = 0.25f;
	pNewAnim6->m_FrameList[3].m_fFrameTime = 0.25f;
	m_vAnimations.push_back(pNewAnim6);

	Animation * pNewAnim7 = new Animation;
	pNewAnim7->m_FrameList.resize(5);
	pNewAnim7->m_FrameList[0].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/Char/MidEvil_ani/Jump/TGA/MidEvilJump_F1.tga");
	pNewAnim7->m_FrameList[1].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/Char/MidEvil_ani/Jump/TGA/MidEvilJump_F2.tga");
	pNewAnim7->m_FrameList[2].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/Char/MidEvil_ani/Jump/TGA/MidEvilJump_F3.tga");
	pNewAnim7->m_FrameList[3].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/Char/MidEvil_ani/Jump/TGA/MidEvilJump_F4.tga");
	pNewAnim7->m_FrameList[4].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/Char/MidEvil_ani/Jump/TGA/MidEvilJump_F5.tga");
	pNewAnim7->m_FrameList[0].m_fFrameTime = 0.25f;
	pNewAnim7->m_FrameList[1].m_fFrameTime = 0.25f;
	pNewAnim7->m_FrameList[2].m_fFrameTime = 0.25f;
	pNewAnim7->m_FrameList[3].m_fFrameTime = 0.25f;
	pNewAnim7->m_FrameList[4].m_fFrameTime = 0.25f;
	m_vAnimations.push_back(pNewAnim7);

	Animation * pNewAnim8 = new Animation;
	pNewAnim8->m_FrameList.resize(4);
	pNewAnim8->m_FrameList[0].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/Char/MidEvil_ani/Walk/TGA/MidEvilWalk_F1.tga");
	pNewAnim8->m_FrameList[1].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/Char/MidEvil_ani/Walk/TGA/MidEvilWalk_F2.tga");
	pNewAnim8->m_FrameList[2].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/Char/MidEvil_ani/Walk/TGA/MidEvilWalk_F3.tga");
	pNewAnim8->m_FrameList[3].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/Char/MidEvil_ani/Walk/TGA/MidEvilWalk_F4.tga");
	pNewAnim8->m_FrameList[0].m_fFrameTime = 0.25f;
	pNewAnim8->m_FrameList[1].m_fFrameTime = 0.25f;
	pNewAnim8->m_FrameList[2].m_fFrameTime = 0.25f;
	pNewAnim8->m_FrameList[3].m_fFrameTime = 0.25f;
	m_vAnimations.push_back(pNewAnim8);

	Animation * pNewAnim9 = new Animation;
	pNewAnim9->m_FrameList.resize(6);
	pNewAnim9->m_FrameList[0].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/Char/Shocked/Shocked_F1.tga");
	pNewAnim9->m_FrameList[1].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/Char/Shocked/Shocked_F2.tga");
	pNewAnim9->m_FrameList[2].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/Char/Shocked/Shocked_F3.tga");
	pNewAnim9->m_FrameList[3].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/Char/Shocked/Shocked_F4.tga");
	pNewAnim9->m_FrameList[4].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/Char/Shocked/Shocked_F5.tga");
	pNewAnim9->m_FrameList[5].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/Char/Shocked/Shocked_F6.tga");
	pNewAnim9->m_FrameList[0].m_fFrameTime = 0.25f;
	pNewAnim9->m_FrameList[1].m_fFrameTime = 0.25f;
	pNewAnim9->m_FrameList[2].m_fFrameTime = 0.25f;
	pNewAnim9->m_FrameList[3].m_fFrameTime = 0.25f;
	pNewAnim9->m_FrameList[4].m_fFrameTime = 0.25f;
	pNewAnim9->m_FrameList[5].m_fFrameTime = 0.25f;
	m_vAnimations.push_back(pNewAnim9);

	Animation * pNewAnim10 = new Animation;
	pNewAnim10->m_FrameList.resize(6);
	//pNewAnim10->m_FrameList[6].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/cloud/Eat/CloudEat_F1.tga");
	pNewAnim10->m_FrameList[0].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/cloud/Eat/CloudEat_F2.tga");
	pNewAnim10->m_FrameList[1].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/cloud/Eat/CloudEat_F3.tga");
	pNewAnim10->m_FrameList[2].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/cloud/Eat/CloudEat_F4.tga");
	pNewAnim10->m_FrameList[3].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/cloud/Eat/CloudEat_F5.tga");
	pNewAnim10->m_FrameList[4].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/cloud/Eat/CloudEat_F6.tga");
	pNewAnim10->m_FrameList[5].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/cloud/Eat/CloudEat_F7.tga");
	pNewAnim10->m_FrameList[0].m_fFrameTime = 0.25f;
	pNewAnim10->m_FrameList[1].m_fFrameTime = 0.25f;
	pNewAnim10->m_FrameList[2].m_fFrameTime = 0.25f;
	pNewAnim10->m_FrameList[3].m_fFrameTime = 0.25f;
	pNewAnim10->m_FrameList[4].m_fFrameTime = 0.25f;
	pNewAnim10->m_FrameList[5].m_fFrameTime = 0.25f;
	//pNewAnim10->m_FrameList[6].m_fFrameTime = 0.25f;
	m_vAnimations.push_back(pNewAnim10);

	Animation * pNewAnim11= new Animation;
	pNewAnim11->m_FrameList.resize(2);
	pNewAnim11->m_FrameList[0].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/cloud/Idle/CloudIdle_F1.tga");
	pNewAnim11->m_FrameList[1].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/cloud/Idle/CloudIdle_F2.tga");
	pNewAnim11->m_FrameList[0].m_fFrameTime = 0.25f;
	pNewAnim11->m_FrameList[1].m_fFrameTime = 0.25f;
	m_vAnimations.push_back(pNewAnim11);

	Animation * pNewAnim12= new Animation;
	pNewAnim12->m_FrameList.resize(4);
	pNewAnim12->m_FrameList[0].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/cloud/Lightning/CloudLightning_F1.tga");
	pNewAnim12->m_FrameList[1].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/cloud/Lightning/CloudLightning_F2.tga");
	pNewAnim12->m_FrameList[2].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/cloud/Lightning/CloudLightning_F3.tga");
	pNewAnim12->m_FrameList[3].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/cloud/Lightning/CloudLightning_F4.tga");
	pNewAnim12->m_FrameList[0].m_fFrameTime = 0.25f;
	pNewAnim12->m_FrameList[1].m_fFrameTime = 0.25f;
	pNewAnim12->m_FrameList[2].m_fFrameTime = 0.25f;
	pNewAnim12->m_FrameList[3].m_fFrameTime = 0.25f;
	m_vAnimations.push_back(pNewAnim12);

	Animation * pNewAnim13= new Animation;
	pNewAnim13->m_FrameList.resize(3);
	pNewAnim13->m_FrameList[0].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/cloud/LightningBolt/LightningBolt_F1.tga");
	pNewAnim13->m_FrameList[1].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/cloud/LightningBolt/LightningBolt_F2.tga");
	pNewAnim13->m_FrameList[2].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/cloud/LightningBolt/LightningBolt_F3.tga");
	pNewAnim13->m_FrameList[0].m_fFrameTime = 0.25f;
	pNewAnim13->m_FrameList[1].m_fFrameTime = 0.25f;
	pNewAnim13->m_FrameList[2].m_fFrameTime = 0.25f;
	m_vAnimations.push_back(pNewAnim13);

	Animation * pNewAnim14= new Animation;
	pNewAnim14->m_FrameList.resize(1);
	pNewAnim14->m_FrameList[0].m_pTexHandle = CTextureManager::GetInstance()->LoadTexture("img/sun/TGA/SunIdle_F1.tga");
	pNewAnim14->m_FrameList[0].m_fFrameTime = 0.25f;
	m_vAnimations.push_back(pNewAnim14);


	return true;
}

Animation *CAnimationEngine::LoadAnimation(int states)
{
	for (unsigned int i = 0; i < m_vAnimations.size(); i++)
	{
		if (states == i)
			return m_vAnimations[i];
	}

	return 0;
}

void CAnimationEngine::Shutdown()
{
	for (unsigned int i = 0; i < m_vAnimations.size(); i++)
	{
		delete m_vAnimations[i];
	}
	m_vAnimations.clear();
}